<?php

$title = 'Create / Edit';
include('../include/header.php');
include('../src/LivedocxBroker.php');

$sql = "select * from resumes where username = 'noauth' order by ID desc limit 1";
$result = mysql_query($sql) or die ('SQL Error : ' . mysql_error());
if(!$result)
{
	echo "No resumes found!  Please create a new resume now!";
}

if (isset($_POST["submit"]))
  {
    // SQL to insert info into database..
    $sql = "INSERT INTO resumes (username, firstName, middleInitial, lastName, addrStreet, addrCityStZip, phone, email, coverText, undergradSchool, undergradDeg, undergradGradDate, undergradLoc, gradSchool, gradDeg, gradGradDate, gradLoc, qualifications, skills, certifications, curEmpName, curEmpLoc, curEmpSup, curEmpSupPhone, curEmpStartDate, curEmpJobTitle, curEmpJobDesc, prevEmpName1, prevEmpLoc1, prevEmpSup1, prevEmpSupPhone1, prevEmpStart1, prevEmpEnd1, prevEmpJobTitle1, prevEmpJobDesc1, prevEmpReason1, prevEmpName2, prevEmpLoc2, prevEmpSup2, prevEmpSupPhone2, prevEmpStart2, prevEmpEnd2, prevEmpJobTitle2, prevEmpJobDesc2, prevEmpReason2, refName1, refContact1, refName2, refContact2, refName3, refContact3, otherInfo) VALUES ('noauth', '$_POST[firstName]', '$_POST[middleInitial]', '$_POST[lastName]', '$_POST[addrStreet]', '$_POST[addrCityStZip]', '$_POST[phone]', '$_POST[email]', '$_POST[coverText]', '$_POST[undergradSchool]', '$_POST[undergradDeg]', '$_POST[undergradGradDate]', '$_POST[undergradLoc]', '$_POST[gradSchool]', '$_POST[gradDeg]', '$_POST[gradGradDate]', '$_POST[gradLoc]', '$_POST[qualifications]', '$_POST[skills]', '$_POST[certifications]', '$_POST[curEmpName]', '$_POST[curEmpLoc]', '$_POST[curEmpSup]', '$_POST[curEmpSupPhone]', '$_POST[curEmpStartDate]', '$_POST[curEmpJobTitle]', '$_POST[curEmpJobDesc]', '$_POST[prevEmpName1]', '$_POST[prevEmpLoc1]', '$_POST[prevEmpSup1]', '$_POST[prevEmpSupPhone1]', '$_POST[prevEmpStart1]', '$_POST[prevEmpEnd1]', '$_POST[prevEmpJobTitle1]', '$_POST[prevEmpJobDesc1]', '$_POST[prevEmpReason1]', '$_POST[prevEmpName2]', '$_POST[prevEmpLoc2]', '$_POST[prevEmpSup2]', '$_POST[prevEmpSupPhone2]', '$_POST[prevEmpStart2]','$_POST[prevEmpEnd2]','$_POST[prevEmpJobTitle2]', '$_POST[prevEmpJobDesc2]', '$_POST[prevEmpReason2]', '$_POST[refName1]', '$_POST[refContact1]', '$_POST[refName2]', '$_POST[refContact2]', '$_POST[refName3]', '$_POST[refContact3]', '$_POST[otherInfo]'); ";
    $resource = mysql_query($sql) or die ('SQL Error : ' . mysql_error());
    $numrows = mysql_affected_rows();
    
    if ($numrows == 1)
      {
	echo "Resume saved";

	// call livedocx broker to generate resume
	$livedoc = new LivedocxBroker();
	$livedoc->setTemplate('default');

	//set the fields
	$row = mysql_fetch_array($result);
	$arrlength = count($tokens);

	for ($x=0; $x<$arrlength; $x++)
	  {
	    $field = $tokens[$x];
	    $livedoc->setField($field, $row[$field]);
	  }
	
	$sql = "SELECT username, ID FROM resumes WHERE username = 'noauth' ORDER BY ID DESC LIMIT 1";
	$result = mysql_query($sql) or die ('SQL Error : ' . mysql_error());
	$row = mysql_fetch_array($result);

	$livedoc->downloadResume('../resumes/' . $row['username'] . '-' . $row['ID'] . '.pdf', 'PDF');
      }
    else if ($numrows == 0)
      {
	echo "Failed to save resume";
      }
  }

$sql = "SELECT * FROM resumes WHERE username = 'noauth' ORDER BY ID DESC LIMIT 1";
$result = mysql_query($sql) or die ('SQL Error : ' . mysql_error());
$row = mysql_fetch_array($result);

if (!isset($row))
  {
    $row = array('firstName','middleInitial','lastName','addrStreet','addrCityStZip','phone','email','coverText','undergradSchool','undergradDeg','undergradGradDate','undergradLoc','gradSchool','gradDeg','gradGradDate','gradLoc','qualifications','skills','certifications','curEmpName','curEmpLoc','curEmpSup','curEmpSupPhone','curEmpStartDate','curEmpJobTitle','curEmpJobDesc','prevEmpName1','prevEmpLoc1','prevEmpSup1','prevEmpSupPhone1','prevEmpStart1','prevEmpEnd1','prevEmpJobTitle1','prevEmpJobDesc1','prevEmpReason1','prevEmpName2','prevEmpLoc2','prevEmpSup2','prevEmpSupPhone2','prevEmpStart2','prevEmpEnd2','prevEmpJobTitle2','prevEmpJobDesc2','prevEmpReason2','refName1','refContact1','refName2','refContact2','refName3','refContact3','otherInfo');
  }

?>
<div class='sixteen columns'>
  <form action='<?php echo $_SERVER["PHP_SELF"]; ?>' method='post'>
    <section class='resume-section'>
      <h3>Cover Letter</h3>
      <div class='resume-input'>
        <input class='full' placeholder='Cover letter...' name='coverText' value="<?php echo $row['coverText']; ?>"></input>
      </div>
    </section>
    <section class='resume-section clearfix'>
      <h3>Contact Info</h3>
      <div class='resume-info'>
        <input class='half' placeholder='First Name' name='firstName' value="<?php echo $row['firstName']; ?>" type='text'>
        <input class='half' maxlength='1' placeholder='Middle Initial' name='middleInitial' value="<?php echo $row['middleInitial']; ?>" type='text'>
        <input class='half' placeholder='Last Name' name='lastName' value="<?php echo $row['lastName']; ?>" type='text'>
        <input class='half' placeholder='Phone' name='phone' value="<?php echo $row['phone']; ?>" type='text'>
        <input class='half' placeholder='Email' name='email' value="<?php echo $row['email']; ?>" type='text'>
        <input class='full' placeholder='Street Address' name='addrStreet' value="<?php echo $row['addrStreet']; ?>" type='text'>
        <input class='full' placeholder='Email' name='addrCityStZip' value="<?php echo $row['addrCityStZip']; ?>" type='text'>
        </div>
    </section>
    <section class='resume-section'>
      <h3>Education</h3>
      <div class='resume-info'>
        <h4>Undergrad</h4>
        <input class='full' placeholder='Undergrad School Name' name='undergradSchool' value="<?php echo $row['undergradSchool']; ?>" type='text'>
        <input class='full' placeholder='Undergrad School Location' name='undergradLoc' value="<?php echo $row['undergradLoc']; ?>" type='text'>
        <input class='half' placeholder='Degree Type &amp; Department' name='undergradDeg' value="<?php echo $row['undergradDeg']; ?>" type='text'>
        <input class='half' placeholder='Graduation Date' name='undergradGradDate' value="<?php echo $row['undergradGradDate']; ?>" type='text'>
        <h4>Graduate's Degree</h4>
        <input class='full' placeholder='Grad School Name' name='gradSchool' value="<?php echo $row['gradSchool']; ?>" type='text'>
        <input class='full' placeholder='Grad School Location' name='gradLoc' value="<?php echo $row['gradLoc']; ?>" type='text'>
        <input class='half' placeholder='Degree Type &amp; Department' name='gradDeg' value="<?php echo $row['gradDeg']; ?>" type='text'>
        <input class='half' placeholder='Graduation Date' name='gradGradDate' value="<?php echo $row['gradGradDate']; ?>" type='text'>
      </div>
    </section>
    <section class='resume-section'>
      <h3>Koalafications</h3>
      <div class='resume-info'>
        <input class='full' placeholder='Skills' name='skills' value="<?php echo $row['skills']; ?>"></input>
        <input class='full' placeholder='Qualifications' name='qualifications' value="<?php echo $row['qualifications']; ?>"></input>
        <input class='full' placeholder='Certifications' name='certifications' value="<?php echo $row['certifications']; ?>"></input>
        <input class='full' placeholder='Any other relevant information' name='otherInfo' value="<?php echo $row['otherInfo']; ?>"></input>
      </div>
    </section>
    <section class='resume-section'>
      <h3>Experience</h3>
      <div class='resume-info'>
        <h4>Current Employer</h4>
        <input class='full' placeholder='Employer Name' name='curEmpName' value="<?php echo $row['curEmpName']; ?>" type='text'>
        <input class='half' placeholder='Location' name='curEmpLoc' value="<?php echo $row['curEmpLoc']; ?>" type='text'>
        <input class='half' placeholder='Start Date' name='curEmpStartDate' value="<?php echo $row['curEmpStartDate']; ?>" type='text'>
        <input class='half' placeholder='Supervisor' name='curEmpSup' value="<?php echo $row['curEmpSup']; ?>" type='text'>
        <input class='half' placeholder='Supervisor phone number' name='curEmpSupPhone' value="<?php echo $row['curEmpSupPhone']; ?>" type='text'>
        <input class='full' placeholder='Job Title' name='curEmpJobTitle' value="<?php echo $row['curEmpJobTitle']; ?>" type='text'>
        <input class='full' placeholder='Job Description' name='curEmpJobDesc' value="<?php echo $row['curEmpJobDesc']; ?>" type='text'>
        <h4>Past Employer #1</h4>
        <input class='full' placeholder='Employer Name' name='prevEmpName1' value="<?php echo $row['prevEmpName1']; ?>" type='text'>
        <input class='full' placeholder='Location' name='prevEmpLoc1' value="<?php echo $row['prevEmpLoc1']; ?>" type='text'>
        <input class='half' placeholder='Start Date' name='prevEmpStart1' value="<?php echo $row['prevEmpStart1']; ?>" type='text'>
        <input class='half' placeholder='End Date' name='prevEmpEnd1' value="<?php echo $row['prevEmpEnd1']; ?>" type='text'>
        <input class='half' placeholder='Supervisor' name='prevEmpSup1' value="<?php echo $row['prevEmpSup1']; ?>" type='text'>
        <input class='half' placeholder='Supervisor phone number' name='prevEmpSupPhone1' value="<?php echo $row['prevEmpSupPhone1']; ?>" type='text'>
        <input class='full' placeholder='Job Title' name='prevEmpJobTitle1' value="<?php echo $row['prevEmpJobTitle1']; ?>" type='text'>
        <input class='full' placeholder='Job Description' name='prevEmpJobDesc1' value="<?php echo $row['prevEmpJobDesc1']; ?>" type='text'>
        <input class='full' placeholder='Reason For leaving' name='prevEmpReason1' value="<?php echo $row['prevEmpReason1']; ?>" type='text'>
        <h4>Past Employer #2</h4>
        <input class='full' placeholder='Employer Name' name='prevEmpName2' value="<?php echo $row['prevEmpName2']; ?>" type='text'>
        <input class='full' placeholder='Location' name='prevEmpLoc2' value="<?php echo $row['prevEmpLoc2']; ?>" type='text'>
        <input class='half' placeholder='Start Date' name='prevEmpStart2' value="<?php echo $row['prevEmpStart2']; ?>" type='text'>
        <input class='half' placeholder='End Date' name='prevEmpEnd2' value="<?php echo $row['prevEmpEnd2']; ?>" type='text'>
        <input class='half' placeholder='Supervisor' name='prevEmpSup2' value="<?php echo $row['prevEmpSup2']; ?>" type='text'>
        <input class='half' placeholder='Supervisor phone number' name='prevEmpSupPhone2' value="<?php echo $row['prevEmpSupPhone2']; ?>" type='text'>
        <input class='full' placeholder='Job Title' name='prevEmpJobTitle2' value="<?php echo $row['prevEmpJobTitle2']; ?>" type='text'>
        <input class='full' placeholder='Job Description' name='prevEmpJobDesc2' value="<?php echo $row['prevEmpJobDesc2']; ?>" type='text'>
        <input class='full' placeholder='Reason for leaving' name='prevEmpReason2' value="<?php echo $row['prevEmpReason2']; ?>" type='text'>
      </div>
    </section>
    <section class='resume-section'>
      <h3>References</h3>
      <div class='resume-info'>
        <h4>Reference #1</h4>
        <input class='full' placeholder='Reference Name and Relationship' name='refName1' value="<?php echo $row['refName1']; ?>" type='text'>
        <input class='full' placeholder='Reference Contact Information' name='refContact1' value="<?php echo $row['refContact1']; ?>" type='text'>
        <h4>Reference #2</h4>
        <input class='full' placeholder='Reference Name and Relationship' name='refName2' value="<?php echo $row['refName2']; ?>" type='text'>
        <input class='full' placeholder='Reference Contact Information' name='refContact2' value="<?php echo $row['refContact2']; ?>" type='text'>
        <h4>Reference #3</h4>
        <input class='full' placeholder='Reference Name and Relationship' name='refName3' value="<?php echo $row['refName3']; ?>" type='text'>
        <input class='full' placeholder='Reference Contact Information' name='refContact3' value="<?php echo $row['refContact3']; ?>" type='text'>
        <h4>Other Information</h4>
        <input class='full' placeholder='Other Info' name='otherInfo' value="<?php echo $row['otherInfo']; ?>" type='text'>
        </div>
    </section>
    <input type='Submit' value='Save!' name='submit'>
  </form>
</div>


<?php

include('../include/footer.php');

?>
